package com.ruoyi.index.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.index.domain.FhIndexPostinfo;
import com.ruoyi.index.service.IFhIndexPostinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 发布信息Controller
 * 
 * @author ruoyi
 * @date 2024-11-12
 */
@RestController
@RequestMapping("/index/postinfo")
public class FhIndexPostinfoController extends BaseController
{
    @Autowired
    private IFhIndexPostinfoService fhIndexPostinfoService;

    /**
     * 查询发布信息列表
     */
    @PreAuthorize("@ss.hasPermi('index:postinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(FhIndexPostinfo fhIndexPostinfo)
    {
        startPage();
        List<FhIndexPostinfo> list = fhIndexPostinfoService.selectFhIndexPostinfoList(fhIndexPostinfo);
        return getDataTable(list);
    }

    /**
     * 导出发布信息列表
     */
    @PreAuthorize("@ss.hasPermi('index:postinfo:export')")
    @Log(title = "发布信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FhIndexPostinfo fhIndexPostinfo)
    {
        List<FhIndexPostinfo> list = fhIndexPostinfoService.selectFhIndexPostinfoList(fhIndexPostinfo);
        ExcelUtil<FhIndexPostinfo> util = new ExcelUtil<FhIndexPostinfo>(FhIndexPostinfo.class);
        util.exportExcel(response, list, "发布信息数据");
    }

    /**
     * 获取发布信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('index:postinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fhIndexPostinfoService.selectFhIndexPostinfoById(id));
    }

    /**
     * 新增发布信息
     */
    @PreAuthorize("@ss.hasPermi('index:postinfo:add')")
    @Log(title = "发布信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FhIndexPostinfo fhIndexPostinfo)
    {
        FhIndexPostinfo fhIndexPostinfo1 = fhIndexPostinfoService.insertFhIndexPostinfo(fhIndexPostinfo);
        return toAjax(1);
    }

    /**
     * 修改发布信息
     */
    @PreAuthorize("@ss.hasPermi('index:postinfo:edit')")
    @Log(title = "发布信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FhIndexPostinfo fhIndexPostinfo)
    {
        return toAjax(fhIndexPostinfoService.updateFhIndexPostinfo(fhIndexPostinfo));
    }

    /**
     * 删除发布信息
     */
    @PreAuthorize("@ss.hasPermi('index:postinfo:remove')")
    @Log(title = "发布信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fhIndexPostinfoService.deleteFhIndexPostinfoByIds(ids));
    }
}
